﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.protocolquotainfo
{
    public partial class Add : lcs.Web.Admin.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                    lcs.BLL.depinfo dbll = new BLL.depinfo();
                    DataSet ds_role = dbll.GetAllList();
                    ddldep.DataSource = ds_role;
                    ddldep.DataTextField = "depname";
                    ddldep.DataValueField = "depid";
                    ddldep.DataBind();
                    lcs.BLL.materialtypeinfo bm = new BLL.materialtypeinfo();
                    ddltype.DataSource = bm.GetAllList().Tables[0];
                    ddltype.DataTextField = "mtname";
                    ddltype.DataValueField = "mtid";
                    ddltype.DataBind();
                    Page.DataBind();
                
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";          
                    
            if (!PageValidate.IsDecimal(txtquota.Text))
            {
                strErr += "配额格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int depid = int.Parse(this.ddldep.SelectedValue);
            int mtid = int.Parse(this.ddltype.SelectedValue);
            int sid = 0;
            if (hfsid.Value != "") sid = int.Parse(hfsid.Value);
            decimal quota = decimal.Parse(this.txtquota.Text);
            if (sid == 0)
            {
                Maticsoft.Common.MessageBox.Show(this, "供应商不能为空！");
                return;
            }            
            lcs.Model.protocolquotainfo model = new lcs.Model.protocolquotainfo();
            model.depid = depid;
            model.mtid = mtid;
            model.sid = sid;
            model.quota = quota;

            lcs.BLL.protocolquotainfo bll = new lcs.BLL.protocolquotainfo();
            bll.Add(model);
            Maticsoft.Common.MessageBox.Show(this, "保存成功！请继续增加！");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
